/*********************************************************
          File Name:16.14.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun 13 Dec 2015 11:21:15 AM CST
**********************************************************/

#ifndef EX_16_14_H_
#define EX_16_14_H_

#include <iostream>
#include <string>
#include <vector>

template<size_t H, size_t W>
class Screen
{
        private:
                size_t hight;
                size_t width;

                std::vector<std::string> contents;
        public:
                Screen() = default;
                Screen(const std::string &s) : 
                        hight(H), width(W), contents(H * W, s) {  }

                friend std::ostream &operator<<(std::ostream &os, Screen<H, W> &s)
                {
                        for(auto &x: s.contents)
                        {
                                os << x << std::endl;
                        }
                        return os;
                }

                friend std::istream &operator>>(std::istream &is, Screen<H, W> &s)
                {
                        std::string tmp, ss;
                        std::getline(is,tmp);

                        if(tmp.length() > s.width)
                                ss = tmp.substr(0, s.width);
                        else
                                ss = tmp;

                        s.contents.clear();

                        for(size_t i = 0; i < s.hight; ++i)
                                s.contents.push_back(ss);

                        return is;
                }
};

#endif
